#pragma once

#include ".\WinCore\WinCore.h"

#define  _APPNAME   _T("Demo Font")

//////////////////////////////////////////////////////////////////////////
// CDemoApp
//////////////////////////////////////////////////////////////////////////
class CDemoApp : public CWinApp
{
public:
	CDemoApp();
	~CDemoApp();

protected:
	bool	InitInstance();
};

//////////////////////////////////////////////////////////////////////////
// CDemoWnd
//////////////////////////////////////////////////////////////////////////
class CDemoWnd : public CWinWnd
{
protected:
	struct TMSGMAP {
		typedef LRESULT (CDemoWnd::*MSGPROC)(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);

		UINT		m_nMsg;
		MSGPROC		m_MsgProc;
	};

public: 
	CDemoWnd(const TCHAR* szAppName = _APPNAME);
	~CDemoWnd();

protected:
	LRESULT		WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);

protected:
	LRESULT		OnCreate(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
	LRESULT		OnDestroy(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
	LRESULT		OnPaint(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
	LRESULT		OnLButtonDown(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
	LRESULT		OnLButtonUp(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
	LRESULT		OnSize(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
	LRESULT		OnCommand(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
private:
	void		PartitionGrid(HDC hDC, RECT* prtGrids, int nGridCount);

	void		DemoFontInfo(HDC hDC);
	
	void		DemoDrawText(HDC hDC, const RECT& rtGrid);
	void		DemoTextout(HDC hDC, RECT& rtGrid);
	void		DemoExtTextout(HDC hDC, RECT& rtGrid);
	void		DemoDrawTextEx(HDC hDC, RECT& rtGrid);
	void		DemoPolyText(HDC hDC, RECT& rtGrid);
	void		DemoTabbedTextOut(HDC hDC, RECT& rtGrid);
	
private:
	void		_GetCharsetAndFaceName(int nCharset, TCHAR* szFaceName, UINT nFaceNameSzie);

	static int CALLBACK _FontNameEnumProc(CONST LOGFONTW* LogFont, CONST TEXTMETRICW* tm, DWORD dwFont, LPARAM lParam);
	void		_UpdateFaceNameList();
	void		_RefreshView();
	void		_UpdateTextAlign();
	void		_UpdateBkMode();	
	void		_UpdateBKColor();
	void		_UpdateTextColor();

	void		_UpdateBoldStatus();
	void		_UpdateItalicStatus();
	void		_UpdateStrikeoutStatus();
	void		_UpdateUnderlineStatus();
	
	bool		_CreateCtrls(HWND hWnd);
	void		_InitCtrls();
private:
	enum {
		CTRLID_CHARSET		= 0,
		CTRLID_FACENAME,	
		CTRLID_ALIGN,
		CTRLID_BKMODE,
		CTRLID_BKCLR,
		CTRLID_TEXTCLR,
		CTRLID_BOLD,
		CTRLID_ITALIC,
		CTRLID_UNDERLINE,
		CTRLID_STRIKEOUT
	};

	HFONT		m_hFont;
	DWORD		m_nTxtAlign;
	DWORD		m_nBkMode;
	COLORREF	m_crBack;
	COLORREF	m_crText;

	bool		m_bItalic;
	bool		m_bBold;
	bool		m_bUnderLine;
	bool		m_bStrikOut;

	static const UINT m_nCtrlCount = 10;
	HWND		m_hCtrls[10];

	static const TMSGMAP MsgMapTable[];
};
